package com.sunny;

import net.sf.cglib.proxy.Enhancer;

/**
 * @Author zsunny
 * @Date 2018/9/20 15:41
 * @Mail zsunny@yeah.net
 */
public class ProxyDemo {

    public Object getProxy(Class clazz){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(clazz);
        enhancer.setCallback(new CglibProxyHandler(new Caculator()));
        return enhancer.create();
    }

    public static void main(String[] args) {

        ProxyDemo proxyDemo = new ProxyDemo();
        Caculator caculator = (Caculator) proxyDemo.getProxy(Caculator.class);
        int res = caculator.add(1, 2);
        System.out.println(res);

    }

}
